package com.cqndt.visual.udp.client;

import com.cqndt.visual.vo.FlightDataVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.integration.ip.udp.UnicastSendingMessageHandler;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.stereotype.Service;

/**
 * Created By marc
 * Date: 2021/5/12  11:20
 * Description:
 */
@Service
public class UdpClient {
    private final static Logger logger = LoggerFactory.getLogger(UdpClient.class);

    @Autowired
    private UnicastSendingMessageHandler unicastSendingMessageHandler;

    public void sendMessage(FlightDataVo message) {
        logger.info("发送UDP: {}", message);
        unicastSendingMessageHandler.handleMessage(MessageBuilder.withPayload(message.toString()).build());
        logger.info("发送成功");
    }
}
